//
//  HPHelpViewController.m
//  ZZTong
//
//  Created by xy on 13-5-20.
//  Copyright (c) 2013年 handpay. All rights reserved.
//

#import "HPHelpViewController.h"
#import "ZZTongColorDefine.h"
#import "HPBorderView.h"


@interface HPHelpViewController (){
    IBOutlet UIActivityIndicatorView *indicatorView;
//    IBOutlet HPBorderView *bordView;
}
@end

@implementation HPHelpViewController
//static NSString* host = @"http://www.handpay.com.cn/web/newzzt/2.0/";

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
       
    }
    return self;
}

- (void)viewDidLoad
{
    NSString *strTitle = [self.screenData objectForKey:@"title"];
    if ([NSString isNilOrEmpty:strTitle]) {
        strTitle = @"帮助中心";
    }
    self.title = strTitle;
    [super viewDidLoad];
    
    NSString* host = @"http://www.handpay.com.cn/web/";
    switch (kVerChannel) {
        case VerChannelLikePay:
            host = [host stringByAppendingString:@"HXLikePay/"];
            break;
        case VerChannelHx:
            host = [host stringByAppendingString:@"newzzt/2.0/"];
            break;
        case VerChannelFFTong:
            host = [host stringByAppendingString:@"FFTONG/"];
            break;
        case VerChannelFengMang:
            host = [host stringByAppendingString:@"FMKJ/"];
            break;
        case VerChannelQianBao:
            host = [host stringByAppendingString:@"QB/"];
            break;
        case VerChannelLeFuBao:
            host = [host stringByAppendingString:@"LFB/"];
            break;
        case VerChannelLangNai:
            host = [host stringByAppendingString:@"LN/"];
            break;
        case VerChannelZCJR:
            host = [host stringByAppendingString:@"ZCJR/"];
            break;
        case VerChannelZXF:
            host = [host stringByAppendingString:@"ZXF/"];
            break;
        case VerChannelXFB:
            host = [host stringByAppendingString:@"XFB/"];
            break;
        case VerChannelHeXin:
            host = [host stringByAppendingString:@"HXIN/"];
            break;
        default:
            break;

    }
    
    NSString* fileName = [self.screenData objectForKey:@"url"];
    if ([NSString isNilOrEmpty:fileName]) {  //帮助信息
//        if (kVerChannel == VerChannelLikePay) {
//            self.helpWebView.hidden = YES;
//            indicatorView.hidden = YES;
//            bordView.hidden = NO;
//            
//            bordView.clipsToBounds = NO;
//            bordView.borderType = BorderTypeSolid;
//            bordView.dashPattern = 4;
//            bordView.spacePattern = 4;
//            bordView.borderWidth = 1;
//            bordView.cornerRadius = 10;
//            bordView.borderColor = UIColorFromRGB(0x85BAF8);
//            [bordView refresh];
//            return;
//        }
        fileName = @"Useinfo";
    }
    NSString* url = [NSString stringWithFormat:@"%@%@.html", host, fileName];
    [self.helpWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
    self.helpWebView.delegate = self;
    
    indicatorView.center = self.helpWebView.center;
    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)dealloc {
    if (indicatorView){
        [indicatorView release];
        indicatorView = nil;
    }
    
    [_helpWebView release];
    [indicatorView release];
//    [bordView release];
    [super dealloc];
}
- (void)viewDidUnload {
    [self setHelpWebView:nil];
    [indicatorView release];
    indicatorView = nil;
    [super viewDidUnload];
}

- (void)showLoading{
    indicatorView.hidden = NO;
    [indicatorView startAnimating];
}

- (void)hideLoading{
    indicatorView.hidden = YES;
    [indicatorView stopAnimating];
}

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
    [self showLoading];
    return YES;
}

- (void)webViewDidStartLoad:(UIWebView *)webView{
    
}

- (void)webViewDidFinishLoad:(UIWebView *)webView{
    [self hideLoading];
}

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{
    [self hideLoading];
}
@end
